//
//  SettingsViewController.m
//  Cachalot
//
//  Created by Adam Cue on 6/29/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SettingsViewController.h"
#import "AboutPageViewController.h"

@implementation SettingsViewController

- (void) viewDidLoad {
   [super viewDidLoad];
   self.navigationItem.title = @"Settings";
}

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
   return toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight;
}

#pragma mark UITableViewDataSource
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   static NSString * identifier = @"SettingsViewControllerCell";
   UITableViewCell * cell = [_tableView dequeueReusableCellWithIdentifier:identifier];
   if(cell == nil) cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
   if(indexPath.section == 0){
      cell.textLabel.text = @"About";
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
   }
   else{
      cell.textLabel.text = @"Show Tutorials"; 
      cell.accessoryType = UITableViewCellAccessoryNone;
   }
   return cell;
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
   return 2;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   return 1;
}

#pragma mark UITableViewDelegate
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   if(indexPath.section == 0){
      AboutPageViewController * aboutVC = [[AboutPageViewController alloc] init];
      [self.navigationController pushViewController:aboutVC animated:YES];
      [aboutVC release];
   }
   else{
      [[NSUserDefaults standardUserDefaults] removeObjectForKey:CACHALOT_MEGAFAUNA_TUTORIAL_KEY];
      [[NSUserDefaults standardUserDefaults] removeObjectForKey:CACHALOT_READING_TUTORIAL_KEY];
      [[NSUserDefaults standardUserDefaults] removeObjectForKey:CACHALOT_LESSON_TUTORIAL_KEY];
      UIAlertView * av = [[[UIAlertView alloc] initWithTitle:@"Tutorials Reset" 
                                                     message:@"Tutorials will be shown again on first view."
                                                    delegate:nil 
                                           cancelButtonTitle:@"OK" 
                                           otherButtonTitles:nil] autorelease];
      [av show];
   }
   [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
